<?php
/**
 * Created by PhpStorm.
 * User: sunqiang
 * Date: 2018/8/20
 * Time: 下午12:04
 */

namespace api\controllers;

use Yii;
use common\helps\tools;
use yii\web\Controller;

class ReportOrderController extends Controller
{
    /**
     * 单店单日销售查询
     */
    public function actionShopSale(){

        $inputParam = Yii::$app->request->post();


        if(!isset($inputParam['start_date']) && empty($inputParam['start_date'])){
            return $this->retJson('却少参数:start_date', 404);
        }

        if(!isset($inputParam['end_date']) && empty($inputParam['end_date'])){
            return $this->retJson('却少参数:end_date', 404);
        }

        if(!isset($inputParam['shopId']) && empty($inputParam['shopId'])){
            return $this->retJson('却少参数:shopId', 404);
        }


        $start_date = $inputParam['start_date'];
        $end_date = $inputParam['end_date'];
        $shopId = $inputParam['shopId'];



        $cmd = Yii::$app->db_report->createCommand("CALL P_dailysale_bystore_allchannel(:start_date,:end_date,:shopId)");
        $cmd->bindParam(':start_date',$start_date,\PDO::PARAM_STR);
        $cmd->bindParam(':end_date',$end_date,\PDO::PARAM_STR);
        $cmd->bindParam(':shopId',$shopId,\PDO::PARAM_INT);
        $data = $cmd->queryAll();


        $this->retJson('ok', 200,$data);
    }


    /**
     * 单店单日，内部销售产品明细查询
     */
    public function actionShopProductSale(){

        $inputParam = Yii::$app->request->post();


        if(!isset($inputParam['start_date']) && empty($inputParam['start_date'])){
            return $this->retJson('却少参数:start_date', 404);
        }

        if(!isset($inputParam['end_date']) && empty($inputParam['end_date'])){
            return $this->retJson('却少参数:end_date', 404);
        }

        if(!isset($inputParam['shopId']) && empty($inputParam['shopId'])){
            return $this->retJson('却少参数:shopId', 404);
        }


        $start_date = $inputParam['start_date'];
        $end_date = $inputParam['end_date'];
        $shopId = $inputParam['shopId'];



        $cmd = Yii::$app->db_report->createCommand("CALL P_dailyproductsale_bystore_allchannel(:start_date,:end_date,:shopId)");
        $cmd->bindParam(':start_date',$start_date,\PDO::PARAM_STR);
        $cmd->bindParam(':end_date',$end_date,\PDO::PARAM_STR);
        $cmd->bindParam(':shopId',$shopId,\PDO::PARAM_INT);
        $data = $cmd->queryAll();


        $this->retJson('ok', 200,$data);
    }



}